function onIssue(user, badge, message) {
	
	document.getElementById("message").innerHTML = message;
	
	var uploaded;
	
	if (message == "EXISTS")
		uploaded = true;
	else
		uploaded = false;
	
	if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
	{ 
		xmlhttp = new XMLHttpRequest();
	}
	else // code for IE6, IE5
	{ 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	/*xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			$response = xmlhttp.responseText;
			if (!strcmp($response, "ERR")) {
				document.getElementById("message").innerHTML = "Impossibile aggiornare DB";
			} else {
				document.getElementById("message").innerHTML = "DB aggiornato";
			}
		}
	}*/

	xmlhttp.open("GET", "update_db.php?b=" + badge + "&u=" + user + "&up=" + uploaded, true);
	xmlhttp.send();
}

function success(user, badge){
	
	var uploaded = true;
	
	if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
	{ 
		xmlhttp = new XMLHttpRequest();
	}
	else // code for IE6, IE5
	{ 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	/*xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			$response = xmlhttp.responseText;
			if (!strcmp($response, "ERR")) {
				document.getElementById("message").innerHTML = "Impossibile aggiornare DB";
			} else {
				document.getElementById("message").innerHTML = "DB aggiornato";
			}
		}
	}*/

	xmlhttp.open("GET", "update_db.php?b=" + badge + "&u=" + user + "&up=" + uploaded, true);
	xmlhttp.send();
	
}

function uploadAll(user, badge_errors, badge_successes){
	var i;
	var uploaded;
	var size_err;
	var size_suc;
	var url;

	
	size_err=badge_errors.length;
	size_suc=badge_successes.length;
	
	if (size_err > 0){
		for (i=0; i<size_err; i++){
			url=badge_errors[i].assertion;
			if (badge_errors[i].reason== "EXISTS")
				uploaded = true;
			else
				uploaded = false;
			
			if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
			{ 
				xmlhttp = new XMLHttpRequest();
			}
			else // code for IE6, IE5
			{ 
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			/*xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
				{
					$response = xmlhttp.responseText;
					if (!strcmp($response, "ERR")) {
						document.getElementById("message").innerHTML = "Impossibile aggiornare DB";
					} else {
						document.getElementById("message").innerHTML = "DB aggiornato";
					}
				}
			}*/

			xmlhttp.open("GET", "update_all_db.php?u=" + user + "&url=" + url + "&up=" + uploaded, true);
			xmlhttp.send();

		}
	}
	if(size_suc > 0){
		uploaded=true;
		for (i=0; i<size_suc; i++){
			url=badge_successes[i];
			
			if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
			{ 
				xmlhttp = new XMLHttpRequest();
			}
			else // code for IE6, IE5
			{ 
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			/*xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
				{
					$response = xmlhttp.responseText;
					if (!strcmp($response, "ERR")) {
						document.getElementById("message").innerHTML = "Impossibile aggiornare DB";
					} else {
						document.getElementById("message").innerHTML = "DB aggiornato";
					}
				}
			}*/

			xmlhttp.open("GET", "update_all_db.php?u=" + user +  "&url=" + url + "&up=" + uploaded, true);
			xmlhttp.send();
		}

	}
}